package com.ny.demo.demo523;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class DeleteSQL {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Connection conn = Sqlconnect.getCont();
        Scanner  scanner = new Scanner(System.in);
        System.out.println("请输入用户id：");
        int id = scanner.nextInt();

    //登录的思路：获取用户名和密码，然后去数据库中查询，如果查询到，则登录成功，否则登录失败
        //编写sql语句
        String sql = "delete FROM users WHERE id = ?";
        PreparedStatement state = conn.prepareStatement(sql);
        state.setInt(1,id);
        int i = state.executeUpdate();
        if (i > 0){
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
